package com.dragon.mmochat.message;

import java.util.ArrayList;
import java.util.List;

import com.dragon.mmochat.MmochatConstant;
import com.dragon.mmochat.model.role.MmochatNpc;
import com.dragon.mmochat.model.role.MmochatPlayer;
import com.skymobi.buffer.SkymobiBuffer;
import com.skymobi.message.SkymobiProtocolMessage;

public class Mmochat_4_14S extends SkymobiProtocolMessage {
	List<MmochatNpc> npcList = new ArrayList<MmochatNpc>();
	MmochatPlayer me;

	public Mmochat_4_14S() {
		setMsgCode(MmochatConstant.MSGCODE_MMOCHAT_S_4_14);
	}

	@Override
	protected void encodeBody(SkymobiBuffer out) {
		if (npcList == null || npcList.size() == 0) {
			return;
		}
		out.putShort((short) npcList.size());
		for (MmochatNpc npc : npcList) {
			out.putInt(npc.getNpcId());
			out.put((byte) npc.getTaskStateValue(me));
		}
	}

	public void addNpc(MmochatNpc npc) {
		npcList.add(npc);
	}

	public void setMe(MmochatPlayer me) {
		this.me = me;
	}

	public boolean hasNpc() {
		return npcList.size() > 0;
	}
}
